﻿/*----------------------------------------------------------------
// Copyright (C) 2011 上海
// 版权所有。 
//
// 文件名：DataAccessTempCardInfo
// 文件功能描述：临时卡资料维护数据访问层
//
// 
// 创建标识：2012-06-29 王冲
//
// 修改标识：
// 修改描述：
//
//
//----------------------------------------------------------------*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DbAdapter.sqldbAdapter;
using System.Data.SqlClient;

namespace DAO.WaiGaoQiao
{
    public class DataAccessTempCardInfo
    {
        /// <summary>
        /// 临时卡信息数量
        /// </summary>
        /// <returns></returns>
        public int GetCount(string where)
        {
            sqldb db = new sqldb();
            string query = "select count(1) from FILE_PERSONNEL_VIEW_TEMP where " + where;
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 获取部门列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetdeptName()
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                string query = "select Dep_ID,Dep_No,deptName from File_Department order by Dep_ID";
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        /// <summary>
        /// 获取临时卡资料表
        /// </summary>
        /// <returns></returns>
        public DataSet GetList(int pagesize, int startindex, string strquery)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select * from (select ROW_NUMBER() OVER(ORDER BY PID ASC) rownumber,* " +
                               "from FILE_PERSONNEL_VIEW_TEMP where " + strquery + ") B "
                             + "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString();
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }

        /// <summary>
        /// 根据编号获取一条临时人员信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public DataSet GetInfoOne(string id)
        {
            sqldb db = new sqldb();
            string query = "select * from FILE_PERSONNEL_VIEW_TEMP where PID = '" + id + "'";
            return db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
        }

        public int SaveTempCardInfoEdit(object[] objper)
        {
            sqldb db = new sqldb();
            string query = "update File_Personnel set PName='" + objper[1] + "',Dep_ID=" + objper[2] + ",EmpNo='" + objper[3] + "',GroupIdDept=" + objper[4] + ",structrueId=" + objper[5] + " where PID='" + objper[0] + "'";
            int count = db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
            return count;
        }

        public int CheckEmpNo(int EmpNo, int PID)
        {
            sqldb db = new sqldb();
            string query = "select COUNT(*) from FILE_PERSONNEL_VIEW where EMPNO='" + EmpNo + "' and PID!=" + PID;
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }

        /// <summary>
        /// 获取岗位列表（用于绑定下拉框）
        /// </summary>
        /// <returns></returns>
        public DataSet GetStructrueName()
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                string query = "select structrueId,structrueName from StructureInformationY3 order by structrueId";
                DataSet ds = db.ExecuteDataset(conn, CommandType.Text, query);
                return ds;
            }
        }
    }
}
